package com.jmga.ecogasfinder.activities.maps.overlays;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Location;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
import com.jmga.ecogasfinder.GasStation;

public class GasStationOverlay extends ItemizedOverlay<OverlayItem> {

	private ArrayList<GasStation> gasStations = new ArrayList<GasStation>();
	private Location location;
	private Context mContext;
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	
	public GasStationOverlay(Drawable defaultMarker) {
		  super(boundCenterBottom(defaultMarker));
	}
	
	public GasStationOverlay(Drawable defaultMarker, Context context) {
		  super(boundCenterBottom(defaultMarker));
		  this.mContext = context;
		}

	public Location getLocation() {
		return this.location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}

	public ArrayList<GasStation> getGasStations() {
		return this.gasStations;
	}

	public void setGasStations(ArrayList<GasStation> gasStations) {
		this.gasStations = gasStations;
	}

	public void addOverlay(OverlayItem overlay) {
		this.mOverlays.add(overlay);
	    populate();
	}
	
	@Override
	protected OverlayItem createItem(int i) {
	  return this.mOverlays.get(i);
	}
	
	@Override
	public int size() {
	  return this.mOverlays.size();
	}
	
	@Override
	protected boolean onTap(int index) {
	  OverlayItem item = this.mOverlays.get(index);
	  if(this.mContext != null) {
		  AlertDialog.Builder dialog = new AlertDialog.Builder(this.mContext);
		  dialog.setTitle(item.getTitle());
		  dialog.setMessage(item.getSnippet());
		  dialog.show();
	  }
	  return true;
	}
}
